package com.ywgt.system.service.impl;

import com.ywgt.utils.WriteJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 未登录或token失效的统一结果处理类
 */
@Component
public class RestAuthorzationEntryPoint extends WriteJson implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        response.setContentType("application/json;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        Map<String,Object> info=new HashMap<>();
        info.put("message","未登录，请先登录");
        this.write(request,response,info);
    }
}
